//
//  ViewController.m
//  沙河机制与文件操作
//
//  Created by dllo on 16/8/1.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "ViewController.h"
#define text_file @"testFile.txt"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor blueColor];
    // HomeDirectory目录
    NSString *homeDirectory = NSHomeDirectory();
    NSLog(@"HomeDirectory目录%@",homeDirectory);
    // document目录
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSLog(@"document目录%@",paths);
    NSString *path = [paths lastObject];
    NSLog(@"%@",path);
    // cache目录
    NSString *path1 = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
    NSLog(@"cache目录%@",path1);
    // libaray目录
    NSString *path2 = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).lastObject;
    NSLog(@"libaray目录%@",path2);
    // temp目录
    NSString *tempDir = NSTemporaryDirectory();
    NSLog(@"temp目录%@",tempDir);
    // 写入文件
    NSString *path_DocumentDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    if (!path_DocumentDirectory) {
        NSLog(@"目录没找到");
    } else {
        NSLog(@"文件路径%@",path_DocumentDirectory);
        NSArray *array = [[NSArray alloc] initWithObjects:@"内容", @"content", nil];
        NSString *filePath_DocumentDirectory = [path_DocumentDirectory stringByAppendingPathComponent:text_file];
        [array writeToFile:filePath_DocumentDirectory atomically:YES];
    }
    // 读取文件
    NSString *get_Paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    NSString *get_fileString = [get_Paths stringByAppendingPathComponent:text_file];
    NSArray *array = [NSArray arrayWithContentsOfFile:get_fileString];
    NSLog(@"%@",array);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
